﻿namespace LxCFD
{
    public struct KahanSum
    {
        private double _Sum;
        private double _LostPart;
        public void Add(double input)
        {
            double add = input - _LostPart;
            double temp = _Sum + add;
            _LostPart = (temp - _Sum) - add;
            _Sum = temp;
        }
        public double GetSum()
        {
            double result = LxTool.RoundOff(_Sum, 12);// double.Parse(_sum.ToString("N10"));
            _Sum = 0;
            _LostPart = 0;
            return result;
        }
    }
}
